package cn.formaggie.service.impl;

import cn.formaggie.dao.SampleDao;
import cn.formaggie.dao.SampleTypeDao;
import cn.formaggie.entity.model.sample.Sample;
import cn.formaggie.entity.model.sample.SampleType;
import cn.formaggie.service.face.SampleTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service("sampleTypeService")
public class SampleTypeServiceImpl implements SampleTypeService {

    @Autowired
    private SampleTypeDao sampleTypeDao;

    @Autowired
    private SampleDao sampleDao;

    @Override
    public List<SampleType> getAllSampleTypes() {
        return sampleTypeDao.getAllSampleTypes();
    }

    @Override
    public List<SampleType> findSampleTypes(Map<String, Object> map) {
        return sampleTypeDao.findSampleTypes(map);
    }

    @Override
    public Integer getSampleTypesCount(Map<String, Object> map) {
        return sampleTypeDao.getSampleTypesCount(map);
    }

    @Override
    public Boolean modifySampleTypeInfo(SampleType sampleType) {
        return sampleTypeDao.modifySampleTypeInfo(sampleType)>0?true:false;
    }

    @Override
    public Boolean addSampleType(SampleType sampleType) {
        return sampleTypeDao.addSampleType(sampleType)>0?true:false;
    }

    @Override
    public Boolean deleteSampleType(Integer id) {
        List<Sample> samples=sampleDao.findSamplesWithTypeId(id);
        if(samples.size()>0){
            return false;
        }
        return sampleTypeDao.deleteSampleType(id);
    }
}
